package com.bckj.freshnow.goods.service;

import com.bckj.freshnow.goods.entity.Goods;
import com.bckj.freshnow.goods.mapper.GoodsMapper;
import com.bckj.freshnow.goods.repo.GoodsRepository;
import com.bckj.freshnow.goods.convert.GoodsConvert;
import com.bckj.freshnow.goods.model.GoodsResponse;
import com.bckj.freshnow.goods.model.GoodsRequest;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品基础表(Goods)service
 *
 * @author makejava
 * @since 2025-04-22 10:07:26
 */
@Service
@RequiredArgsConstructor
public class GoodsService {

    private final GoodsRepository goodsRepository;
    private final GoodsMapper goodsMapper;
    private final GoodsConvert goodsConvert;
	
    /**
     * 列表
     *
     * @param request req
     * @return list
     */
    public List<GoodsResponse> findAll(GoodsRequest request){
        return goodsMapper.findAll(request);
    }
    
    /**
     * 详情
     *
     * @param id id
     * @return vo
     */
    public GoodsResponse details(Long id) {
        Goods entity = goodsRepository.getById(id);
        return goodsConvert.bean2Response(entity);
    }
    
    /**
	 * 增加
	 *
	 * @param request req
	 * @return boolean
	 */
    public boolean save(GoodsRequest request) {
        Goods data = goodsConvert.request2Bean(request);
        return goodsRepository.save(data);
    }
    
    /**
	 * 修改
	 *
	 * @param request req
	 * @return boolean
	 */
	public boolean update(GoodsRequest request) {
        Goods data = goodsConvert.request2Bean(request);
        return goodsRepository.updateById(data);
	}

	/**
	 * 根据Id移除
	 *
	 * @param id id
	 * @return boolean
	 */
	public boolean remove(Long id) {
		return goodsRepository.removeById(id);
	}
}

